/**
 * 地理对象集合组件
 * @example
 * <CesiumProjectContents
 *  scene={scene}
 *  dataSources={dataSources}
 *  icons={icons}
 *  labels={labels}
 *  polylines={polylines}
 *  cesium3DTilesets={cesium3DTilesets}
 *  czml={czml}
 * />
 */
const CesiumProjectContents = React.createClass({
	displayName:'CesiumProjectContents',
    componentWillMount(){
        /**
         * 图表集合
         * @type {Cesium.BillboardCollection}
         */
        this.billboards = new Cesium.BillboardCollection();
        /**
         * 标签集合
         * @type {Cesium.LabelCollection}
         */
        this.labels = new Cesium.LabelCollection();
        /**
         * 线要素集合
         * @type {Cesium.PolylineCollection}
         */
        this.polylines = new Cesium.PolylineCollection();
        /**
         * 地理实体总集合
         * @type {Array}
         */
        this.primitiveCollections = [this.billboards,this.labels,this.polylines];

        const scene = this.props.scene;
        if(scene){
            this.primitiveCollections.forEach((primitiveCollection)=>scene.primitives.add(primitiveCollection));
        }
    },
    componentWillUnmount(){
        this.primitiveCollections.forEach(function(primitiveCollection){
            if(!primitiveCollection.isDestroyed()){
                primitiveCollection.destroy();
            }
        });

        const scene = this.props.scene;

        if(scene && !scene.isDestroyed() && scene.primitives){
            this.primitiveCollections.forEach((primitiveCollection)=>scene.primitives.remove(primitiveCollection));
        }
    },

    render(){
        let renderedPolylines = null;
        if(this.props.polylines){
            const polylines = this.polylines;
            renderedPolylines = this.props.polylines.map((polyline,index)=>{
                return (
                    <CesiumPolyline
                        coords={polyline}
                        polylines={polylines}
                        key={index}
                    />
                )
            });
        }
        return (
            <span>
                {renderedPolylines}
            </span>
        )
    }
});